Current Location: Home> Function Categories> date

date

Format local time/date
Name:date
Category:Date and time
Programming Language:php
One-line Description:Format local date and time.

Definition and usage

date() function formats the local date and time and returns the formatted date string.

Example

Format local date and time and return the formatted date string:

 <?php
// Output day
echo date ( "l" ) . "<br>" ;

// Output day, date, month, year, time AM or PM
echo date ( "l jS \of FY h:i:s A" ) ;
?>

Try it yourself

grammar

 date ( format , timestamp ) ;
parameter describe
format

Required. Specifies the format of the output date string. The following characters can be used:

  • d - What day of the month (from 01 to 31)
  • D - Text representation of the day of the week (in three letters)
  • j - What day of the month, without leading zeros (1 to 31)
  • l (lowercase of 'L') - Complete textual representation of the day of the week
  • N - ISO-8601 digital format representation of the day of the week (1 means Monday, 7 means Sunday)
  • S - English ordinal suffix for the day of the month (2 characters: st, nd, rd, or th. Used with j)
  • w - The number of days of the week (0 means Sunday, 6 means Saturday)
  • z - What day of the year (from 0 to 365)
  • W - In ISO-8601 numeric format, represent the weekly numbers of the year (weekly starts from Monday [Monday])
  • F - Full text representation of the month (January to December)
  • m - numerical representation of the month (from 01 to 12)
  • M - Short text representation of the month (in three letters)
  • n - The number of months is represented without leading zeros (1 to 12)
  • t - the number of days included in a given month
  • L - Whether it is a leap year (1 if it is a leap year, otherwise it is 0)
  • o - Year numbers under ISO-8601 standard
  • Y - Four digit representation of year
  • y - Double digit representation of year
  • a - lowercase form: am or pm
  • A - capital form: AM or PM
  • B - Swatch Internet Time (000 to 999)
  • g - 12-hour system without leading zeros (1 to 12)
  • G - 24-hour system without leading zeros (0 to 23)
  • h - 12-hour system with leading zeros (01 to 12)
  • H - 24-hour system with leading zeros (00 to 23)
  • i - points, with leading zeros (00 to 59)
  • s - seconds, with leading zeros (00 to 59)
  • u - Microseconds (newly added in PHP 5.2.2)
  • e - Time zone identifier (for example: UTC, GMT, Atlantic/Azores)
  • I (capsular form of i) - whether the date is in daylight saving time (1 if it is daylight saving time, otherwise it is 0)
  • O - The difference in Greenwich Time (GMT), in hours (Example: +0100)
  • P - The difference in Greenwich time (GMT), in hours: minutes (newly added in PHP 5.1.3)
  • T - Abbreviation of time zone (example: EST, MDT)
  • Z - Time zone offset in seconds. The offset in the time zone west of UTC is negative (-43200 to 50400)
  • c - ISO-8601 standard date (for example, 2013-05-05T16:34:42+00:00)
  • r - Date in RFC 2822 format (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
  • U - Number of seconds elapsed since the Unix Era (January 1 1970 00:00:00 GMT)

Also, the following predefined constants (available as of PHP 5.1.0):

  • DATE_ATOM - Atom (for example: 2013-04-12T15:52:01+00:00)
  • DATE_COOKIE - HTTP Cookies (for example: Friday, 12-Apr-13 15:52:01 UTC)
  • DATE_ISO8601 - ISO-8601 (for example: 2013-04-12T15:52:01+0000)
  • DATE_RFC822 - RFC 822 (example: Fri, 12 Apr 13 15:52:01 +0000)
  • DATE_RFC850 - RFC 850 (example: Friday, 12-Apr-13 15:52:01 UTC)
  • DATE_RFC1036 - RFC 1036 (example: Fri, 12 Apr 13 15:52:01 +0000)
  • DATE_RFC1123 - RFC 1123 (Example: Fri, 12 Apr 2013 15:52:01 +0000)
  • DATE_RFC2822 - RFC 2822 (Fri, 12 Apr 2013 15:52:01 +0000)
  • DATE_RFC3339 - Same as DATE_ATOM (starting with PHP 5.1.3)
  • DATE_RSS - RSS (Fri, 12 Aug 2013 15:52:01 +0000)
  • DATE_W3C - World Wide Web Alliance (for example: 2013-04-12T15:52:01+00:00)
timestamp Optional. Unix timestamps that specify integers. The default is the current local time (time()).
Similar Functions
Popular Articles